<template>
	<view class="background purchase-list" v-loading="loading">
		<scroll-view class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower"
			@scrolltoupper="scrolltoupper">
			<view class="" style="padding: 0px 12px 10px 12px;">
				<view class="el_selects flex jcfe">
					<el-select v-model="selectValue" @change="optionClick" placeholder="请选择" size="mini"
						style="width: 134px;">
						<el-option v-for="item in options" :key="item.dictValue" :label="item.dictLabel"
							:value="item.dictValue">
						</el-option>
					</el-select>
				</view>
				<ComponyHearder :data="ComponyHearderData" />
				<view class="index_header">
					<view class="index_header_top flex">
						<text @click="headerClick(item,index)" v-for="(item,index) in HeadersData" :key="index"
							:class="indexHeaderValue==index?'indexBack1 fontw700 fonts14':'indexBack2 fonts14'">{{item.label}}{{item.number>0?`(${item.number})`:``}}</text>
					</view>
					<view class="index_header_bottom" v-if="indexHeaderValue!=2">
						<el-input placeholder="搜索职位\公司名称" v-model="form.searchValue" class="input-with-select"
							size="mini">
							<el-button style="margin-bottom: -5px;background-color: #2F6CBC;" slot="append"
								type="primary" icon="el-icon-search" size="mini" @click="search()"></el-button>
						</el-input>
					</view>
				</view>
				<view class="" v-if="indexHeaderValue!=2" @click="detail(item)" v-for="item in datas">
					<Inventory :data="item" />
				</view>
				<view class="Inventory_compony" v-if="indexHeaderValue==2">
					<p class="fontc3d fonts12 fontz">
						{{homeData[1].contentContents}}
					</p>
					<image v-for="item in imageData" :src="item" mode=""
						style="max-width: 100%;margin: auto;margin:10px 0;"></image>
				</view>
				<view class="" v-if="indexHeaderValue!=2">
					<p class="more" v-if="onMore">没有更多了~</p>
					<p class="more" v-if="loading">加载中...</p>
				</view>
			</view>


		</scroll-view>


	</view>
</template>

<script>
	import {
		getselect,
		getlist,
		homeConfiguration
	} from "@/api/index"
	import ComponyHearder from "../components/ComponyHeader.vue"
	import Inventory from "../components/Inventory.vue"
	export default {
		components: {
			ComponyHearder,
			Inventory,
		},
		data() {
			return {
				onMore: false,
				loading: false,
				totalBool: true,
				status: 'more',
				indexHeaderValue: 0,
				input3: "",
				HeadersData: [{
						label: "全部职位",
						number: "0",
						id: 0
					},
					{
						label: "紧急职位",
						number: "0",
						id: 1
					},
					{
						label: "公司信息",
						number: "0",
						id: 2
					}
				],
				title: 'Hello',
				datas: [],
				selectValue: "",
				options: [],
				form: {
					positionName: "", //职位名称
					pageNum: 1,
					pageSize: 10,
					urgentPosition: "",
					positionType: ""
				},
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				homeData: [],
				homeDataTitle: "",
				imageData: [],
				ComponyHearderData: {
					img: "",
					title: "",
					companyType: "",
					companySize: "",
					companyIndustry: "",
					address: "",
					bool: 0
				},
				loading: false
			}
		},
		onLoad() {
			this.loading = true
			this.getselectApi_().then(res => {
				this.getselectApi()
				this.homeConfigurationApi()
			})

		},
		onPullDownRefresh() {
			this.form.pageNum = 1
			this.getlistApi(this.form)
		},
		methods: {
			search() {
				this.form.pageNum = 1
				this.getlistApi(this.form)
			},
			headerClick(item, index) {
				this.form.pageNum = 1
				this.indexHeaderValue = index
				if (this.indexHeaderValue == 0) {
					this.form.urgentPosition = ""
				} else {
					this.form.urgentPosition = 0
				}
				if (this.indexHeaderValue == 2) {
					return
				}
				this.getlistApi(this.form)
			},
			evaluationClick(item) {
				uni.navigateTo({
					url: "/pages/index/evaluation/evaluation?id=" + item + "&type=0"
				})
			},
			getlistApi(params) {
				this.loading = true
				getlist(params).then((res) => {
					this.loading = false
					console.log(res);
					if (this.form.pageNum == 1) {
						this.datas = res.rows
					} else {
						this.datas = [...this.datas, ...res.rows]
					}
					console.log(this.datas.length, res.total);
					if (this.datas.length == res.total) {
						this.onMore = true
						this.totalBool = false
						setTimeout(() => {
							this.onMore = false
						}, 2000)
					} else {
						this.totalBool = true
					}
					uni.stopPullDownRefresh()
				})
			},
			detail(item) {
				uni.navigateTo({
					url: "/pages/index/position/position?data=" + JSON.stringify(item)
				})
			},
			getselectApi() {
				let params = "position_type"
				getselect(params).then(res => {
					console.log(res);
					this.options = [...[{
						dictValue: "",
						dictLabel: "全部"
					}], ...res.data]
					this.HeadersData = [{
							label: "全部职位",
							number: "0",
							id: 0
						},
						{
							label: "紧急职位",
							number: "0",
							id: 1
						},
						{
							label: "公司信息",
							number: "0",
							id: 2
						}
					]
					this.selectValue = this.options[0].dictValue
					this.form.positionType = this.selectValue
					this.getlistApi(this.form)
				})
			},
			optionClick() {
				this.form.positionType = this.selectValue
				this.indexHeaderValue = 0
				this.form.urgentPosition = 1
				if (this.selectValue == 1) {
					this.HeadersData = [{
							label: "全部职位",
							number: "0",
							id: 0
						},
						{
							label: "紧急职位",
							number: "0",
							id: 1
						},
						{
							label: "公司信息",
							number: "0",
							id: 2
						}
					]
				} else {
					this.HeadersData = [{
							label: "全部职位",
							number: "0",
							id: 0
						},
						{
							label: "紧急职位",
							number: "0",
							id: 1
						}
					]
				}
				this.form.pageNum = 1
				this.getlistApi(this.form)
			},
			homeConfigurationApi() {
				homeConfiguration().then(res => {
					console.log("home_pic",res);
					this.homeData = res.data
					this.ComponyHearderData.title = res.data[0].contentContents
					// this.ComponyHearderData.img = res.data[3].configurationOssUrls //logo
					// this.imageData = res.data[4].configurationOssUrls.split(",")
				})
			},
			scrolltolower(event) {
				console.log("页码:",this.form.pageNum);
				if (this.indexHeaderValue == 2) {
					return
				}
				if (!this.totalBool) {
					this.onMore = true
					this.totalBool = false
					setTimeout(() => {
						this.onMore = false
					}, 2000)
					return
				}
				this.form.pageNum++;
				this.getlistApi(this.form)
			},

			scroll(e) {
				// 重新设置pulldown
				this.setPullDown(e.detail.scrollTop < 10)
			},

			scrolltoupper() {

			},
			async getselectApi_() {
				await getselect("requirements_years").then(res => {
					// console.log("工作年限:",res);
					uni.setStorageSync("requirements_years", res.data)
				})
				await getselect("education").then(res => {
					// console.log("学历:",res);
					uni.setStorageSync("education", res.data)
				})
				await getselect("company_type").then(res => {
					// console.log("公司性质:",res);
					uni.setStorageSync("company_type", res.data)
				})
				await getselect("company_size").then(res => {
					// console.log("公司规模:",res);
					uni.setStorageSync("company_size", res.data)
				})
				await getselect("company_industry").then(res => {
					// console.log("所属行业:",res);
					uni.setStorageSync("company_industry", res.data)
				})
				await getselect("position_nature").then(res => {
					// console.log("职位性质:",res);
					uni.setStorageSync("position_nature", res.data)
				})
				await getselect("welfare_treatment").then(res => {
					// console.log("福利:",res);
					uni.setStorageSync("welfare_treatment", res.data)
				})
				await getselect("sys_yes_no").then(res => {
					// console.log("是否:",res);
					uni.setStorageSync("sys_yes_no", res.data)
				})
				await getselect("sys_user_sex").then(res => {
					// console.log("性别:",res);
					uni.setStorageSync("sys_user_sex", res.data)
				})
				await getselect("key_population_information").then(res => {
					// console.log("重点人群:",res);
					uni.setStorageSync("key_population_information", res.data)
				})
				await getselect("marriage").then(res => {
					// console.log("婚姻:",res);
					uni.setStorageSync("marriage", res.data)
				})
				await getselect("position_nature").then(res => {
					// console.log("工作性质:",res);
					uni.setStorageSync("position_nature", res.data)
				})
				await getselect("salary").then(res => {
					// console.log("薪资:",res);
					uni.setStorageSync("salary", res.data)
				})
				await getselect("arrival_time").then(res => {
					// console.log("到岗时间:",res);
					uni.setStorageSync("arrival_time", res.data)
				})
				await getselect("status_of_job_hunting").then(res => {
					// console.log("求职状态:",res);
					uni.setStorageSync("status_of_job_hunting", res.data)
				})
				await getselect("proficiency_level").then(res => {
					// console.log("技能熟练度:",res);
					uni.setStorageSync("proficiency_level", res.data)
				})
				await getselect("political_outlook").then(res => {
					// console.log("政治面貌:",res);
					uni.setStorageSync("political_outlook", res.data)
				})
				await getselect("interview_type").then(res => {
					// console.log("面试方式:",res);
					uni.setStorageSync("interview_type", res.data)
				})
				await getselect("sys_certificate_type").then(res => {
					// console.log("面试方式:",res);
					uni.setStorageSync("sys_certificate_type", res.data)
				})
				await getselect("work_nature").then(res => {
					// console.log("面试方式:",res);
					uni.setStorageSync("work_nature", res.data)
				})
				await this.statusBack()
			},
			statusBack() {
				this.loading = false
				return true
			}

		}
	}
</script>

<style lang="scss" scoped>
	.more {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 30px;
		width: 100%;
		font-size: 14px;
		color: #3D3D3D;
	}

	.purchase-list {
		background-color: #f5f5f5;
		height: calc(100vh - 50px);
		overflow: hidden;

		.purchase-body {
			height: calc(100vh - 50px);
			overflow-y: auto;

			&::-webkit-scrollbar {
				display: none;
				/*隐藏滚动轴*/
			}
		}
	}

	.el_selects {
		margin: 7px 0px;
	}

	.indexBack1 {
		color: #2F6CBC;
	}

	.indexBack2 {
		color: #3D3D3D;
	}

	.index_header {
		margin-top: 8px;
		padding: 14px;
		// height: 54px;
		background: #FFFFFF;
		border-radius: 0px 0px 0px 0px;
		opacity: 1;

		.index_header_top {
			text {
				margin-right: 24px;
			}
		}

		.index_header_bottom {
			margin-top: 13px;
		}
	}

	.Inventory_compony {
		margin-top: 8px;
		padding: 12px 20px;
		background: #FFFFFF;
	}
</style>
